<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>Document</title>
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
		<link rel="stylesheet" type="text/css" href="styles/simditor.css" />
		<script src="jquery.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
		<script type="text/javascript" src="scripts/module.min.js"></script>
		<script type="text/javascript" src="scripts/hotkeys.min.js"></script>
		<script type="text/javascript" src="scripts/uploader.min.js"></script>
		<script type="text/javascript" src="scripts/simditor.min.js"></script>
		<style type="text/css">
			#yulan {
				width: 40px;
				height: 40px;
			}
		</style>
	</head>

	<body>
		<div class="container">
			<div style="background-color: #FF6600;">
				<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">小说录入</button>
				<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myNovel">章节录入</button>
			</div>
			<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title">Modal title</h4>
						</div>
						<div class="modal-body">
							<div class="form-group">
								<img src="" alt="" id="yulan" />
								<label for="user">小说封面</label>
								<input type="file" class="form-control" id="novel_image">
							</div>
							<div class="form-group">
								<label for="user">小说名字</label>
								<input type="text" class="form-control" id="user" placeholder="小说名字">
							</div>
							<div class="form-group">
								<label for="user">小说简介</label>
								<input type="text" class="form-control" id="novel_jianj">
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-primary" id="novel_lu_btn">录入</button>
						</div>
					</div>
				</div>
			</div>
			<div class="modal fade" id="myNovel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							<h4 class="modal-title">Modal title</h4>
						</div>
						<div class="modal-body">
							<div class="form-group">
								<label for="user">小说章节</label>
								<input type="text" class="form-control" id="novel_list">
							</div>
							<div>
								<label for="text">内容</label>
								<textarea id="editor" placeholder="Balabala" autofocus></textarea>
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" class="btn btn-primary" id="novel_list_btn">录入</button>
						</div>
					</div>
				</div>
			</div>
		</div>

	</body>
	<script type="text/javascript" src="jquery.js"></script>
	<script>
		var editor = new Simditor({
			textarea: $('#editor')
		});
		var href = 'http://localhost:8000'
		var loginuid = location.href.split('?')[1].split('&')[0].split('=')[1]
		var author = location.href.split('?')[1].split('&')[1].split('=')[1]
		console.log(loginuid, author)
		var img_url = ''
		//上传小说封面
		novel_image.onchange = function() {
			var f = novel_image.files[0]
			var d = new FormData
			d.append('img', f)
			$.ajax({
				type: "post",
				url: href + "/files/img",
				data: d,
				contentType: false,
				processData: false,
				success(data) {
					console.log(data)
					img_url = href + data
					$('#yulan').attr('src', img_url)
				}
			});
		}
		var searchuid = ''
		novel_lu_btn.onclick = function() {
			if(user.value == '' || novel_jianj.value == '') {
				alert('内容不能为空')
			} else {
				$.ajax({
					type: "post",
					url: href + "/users/novellu",
					data: {
						fm: img_url,
						mz: user.value,
						Jj: novel_jianj.value,
						lu: loginuid,
						Zz: author
					},
					success(data) {
						console.log(data)
						//					$('#myModal').modal('hide')
						$.ajax({
							type: "post",
							url: href + "/users/zhj",
							data: {
								mz: user.value
							},
							success(data) {
								console.log(data)
								searchuid = data[0].uid
							}
						});
//						$('#myModal').modal('hide')
						user.value = ''
						novel_jianj.value = ''
					}
				});
			}
		}
		novel_list_btn.onclick = function() {
			if(novel_list.value == '' || $('.simditor-body').html() == '') {
				alert('内容不能为空')
			} else {
				$.ajax({
					type: "post",
					url: href + "/users/novellist",
					data: {
						bookl: novel_list.value,
						searchuid: searchuid,
						cont: $('.simditor-body').html()
					},
					success(data) {
						console.log(data)
					}
				});
			}
		}
	</script>

</html>